<?php
/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the  Academic Free License (AFL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to support@zprofess.com so we can send you a copy immediately.
 *
 * @category   	Prestashop module
 * @package		Help Desk
 * @version 	1.0
 * @author 		Kurosaki <kurosaki@zprofess.com>
 * @copyright   Copyright (c) 2012 ZPROFESS. (http://zprofess.com)
 * @license    	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
/**
 * @see Zmodule
 */

require_once(_PS_MODULE_DIR_.'zhelpdesk/lib/zprofess/Zhelpdeskmodule.php');
require_once(_PS_MODULE_DIR_.'zhelpdesk/classes/ZdepartmentObject.php');

class ZhelpdeskConfig extends Zhelpdeskmodule {	
	/**
	 * Destroy var config
	 * Configuration::deleteByName('ZCP_VERSION');
	 * @return boolean
	 */
 	public function destroyConfiguration () {
 		/*Genaral Tab*/
 		Configuration::deleteByName('ZHELPDESK_NOTIFY_MISSED_TICKET');
 		Configuration::deleteByName('NOTIFY_STAFF_INTERVAL');
 		Configuration::deleteByName('AUTO_CLOSE_TIME');
 		Configuration::deleteByName('ALLOW_TO_SELECT_ORDER_IN_FO');
 		Configuration::deleteByName('ALLOW_TO_SELECT_PRIORITY_IN_FO');
 		Configuration::deleteByName('ALLOW_TO_UPLOAD_FILE_IN_FO');
 		Configuration::deleteByName('WORKING_TIME');
 		Configuration::deleteByName('WORKING_DAY');
 		Configuration::deleteByName('WORKING_TIME_Monday');
		Configuration::deleteByName('WORKING_TIME_Tuesday');
		Configuration::deleteByName('WORKING_TIME_Wednesday');
		Configuration::deleteByName('WORKING_TIME_Thursday');
		Configuration::deleteByName('WORKING_TIME_Friday');
		Configuration::deleteByName('WORKING_TIME_Saturday');
		Configuration::deleteByName('WORKING_TIME_Sunday');
 		
 		/*End Genaral Tab*/
 		/*Gateway Tab*/
 		Configuration::deleteByName('ZHELPDESK_SERVER');
		Configuration::deleteByName('ZHELPDESK_USER');
		Configuration::deleteByName('ZHELPDESK_PASSWORD');
		Configuration::deleteByName('ZHELPDESK_ENCRYPTION');
		Configuration::deleteByName('ZHELPDESK_PORT');
		Configuration::deleteByName('ZHELPDESK_DEFAULF_DEPARTMENT');
		/*End Gateway Tab*/
		
		/*Gateway Tab*/
		Configuration::deleteByName('ZHELPDESK_SERVER');
		Configuration::deleteByName('ZHELPDESK_USER');
		Configuration::deleteByName('ZHELPDESK_PASSWORD');
		Configuration::deleteByName('ZHELPDESK_ENCRYPTION');
		Configuration::deleteByName('ZHELPDESK_PORT');
		Configuration::deleteByName('ZHELPDESK_DEFAULF_DEPARTMENT');
		/*End Gateway Tab*/
		
		/*Tab front office tab*/
		Configuration::deleteByName('ZHD_NB_MESS_D_TICKET');
		Configuration::deleteByName('ZHD_NB_LIST_TICKET');
		Configuration::deleteByName('ZHD_COLUMN');
		Configuration::deleteByName('ZHD_BLOCK_MY_ACCOUNT');
		/*End Tab front office tab*/
 		return true;
	} 
    /**
     * Init var config
     * 
     * @return boolean
     */
	public function initConfiguration() {
		
		/*Genaral Tab*/
		Configuration::updateValue('ZHELPDESK_NOTIFY_MISSED_TICKET',0);
		Configuration::updateValue('NOTIFY_STAFF_INTERVAL',0);
		Configuration::updateValue('AUTO_CLOSE_TIME',0);
		Configuration::updateValue('ALLOW_TO_SELECT_ORDER_IN_FO',1);
		Configuration::updateValue('ALLOW_TO_SELECT_PRIORITY_IN_FO',1);
		Configuration::updateValue('ALLOW_TO_UPLOAD_FILE_IN_FO',1);
		Configuration::updateValue('WORKING_TIME','08:00-12:00 GMT+7;13:30-17:00 GMT+7');
		Configuration::updateValue('WORKING_DAY','Monday,Tuesday,Wednesday,Thursday,Friday');
		
		Configuration::updateValue('WORKING_TIME_Monday','08:30 AM-12:00 PM;01:30 PM-05:00 PM');
		Configuration::updateValue('WORKING_TIME_Tuesday','08:30 AM-12:00 PM;01:30 PM-05:00 PM');
		Configuration::updateValue('WORKING_TIME_Wednesday','08:30 AM-12:00 PM;01:30 PM-05:00 PM');
		Configuration::updateValue('WORKING_TIME_Thursday','08:30 AM-12:00 PM;01:30 PM-05:00 PM');
		Configuration::updateValue('WORKING_TIME_Friday','08:30 AM-12:00 PM;01:30 PM-05:00 PM');
		Configuration::updateValue('WORKING_TIME_Saturday','08:30 AM-12:00 PM;01:30 PM-05:00 PM');
		Configuration::updateValue('WORKING_TIME_Sunday','08:30 AM-12:00 PM;01:30 PM-05:00 PM');
		
		/*End Genaral Tab*/
		/*Gateway Tab*/
		Configuration::updateValue('ZHELPDESK_SERVER','');
		Configuration::updateValue('ZHELPDESK_USER','');
		Configuration::updateValue('ZHELPDESK_PASSWORD','');
		Configuration::updateValue('ZHELPDESK_ENCRYPTION',''); 
		Configuration::updateValue('ZHELPDESK_PORT','');
		Configuration::updateValue('ZHELPDESK_DEFAULF_DEPARTMENT',1);
		/*End Gateway Tab*/
		$langs = Language::getLanguages (false);
		$array1 = array ();
		foreach ($langs as $lang) {
			$array1 [$lang['id_lang']] = '<p>Hi {name_moderator}, you get a new ticket is sent from customer name {name_customer}, email {email_customer}</p><p>{content}</p><p>Please reply to this email within 24 hours</p>';
		}
		Configuration::updateValue('NEW_TICKET_TEMPLATE_FOR_STAFF',$array1,true);
		
		$array2 = array ();
		foreach ($langs as $lang) {
			$array2 [$lang['id_lang']] = 'You\'ve been had reply customer,<p>Ticket is sent from the client name {name_customer}, email {email_customer}</p><p>{content}</p><p>Please reply to this email within 24 hours</p>';
			
		}
		Configuration::updateValue('UD_TICKET_TEMPLATE_FOR_STAFF',$array2,true);
		
		$array3 = array ();
		foreach ($langs as $lang) {
			$array3 [$lang['id_lang']] = '<p>Thank you for using our position, this is the reply mail content<p></p>{content}</p><p>Please reply to this email within 24 hours</p>';
		}
		Configuration::updateValue('UD_TICKET_TEMPLATE_FOR_CUSTOMER',$array3,true);
		
		$array4 = array ();
		foreach ($langs as $lang) {
			$array4 [$lang['id_lang']] = '<p>Hi {name_staff}, you\'ve been assigned to a ticket to {name_moderator} processor</p><p>Ticket is sent from the client name {name_customer}, email {email_customer}</p><p>Subject {subject}</p><p>Please reply to this email within 24 hours</p>'; 
			
		}							
		Configuration::updateValue('ASSIGNED_TICKET_TEMPLATE',$array4,true);
		
		$array5 = array ();
		foreach ($langs as $lang) {
			$array5 [$lang['id_lang']] = 'You\'ve been had miss ticket,<p>Ticket is sent from the client name {name_customer}, email {email_customer}</p> <p>{content}</p><p>Please reply to this email within 24 hours</p>';
		}	
		Configuration::updateValue('MISSED_TICKET_TEMPLATE',$array5,true);
		/*Tab front office tab*/
		Configuration::updateValue('ZHD_NB_MESS_D_TICKET',10);
		Configuration::updateValue('ZHD_NB_LIST_TICKET',10);
		Configuration::updateValue('ZHD_COLUMN',1);
		Configuration::updateValue('ZHD_BLOCK_MY_ACCOUNT',1);
		/*End Tab front office tab*/
		return true;
	}
	
	/**
	 * process date post from form config
	 * 
	 * @return void
	 */
	private function _postProcess()
	{
		
		$msg="";		
		if (Tools::isSubmit('submitGenaralTab')){
			Configuration::updateValue('ZHELPDESK_NOTIFY_MISSED_TICKET',(int)Tools::getValue('ZHELPDESK_NOTIFY_MISSED_TICKET',0));
			Configuration::updateValue('NOTIFY_STAFF_INTERVAL',(int)Tools::getValue('NOTIFY_STAFF_INTERVAL',0));
			Configuration::updateValue('AUTO_CLOSE_TIME',(int)Tools::getValue('AUTO_CLOSE_TIME',0));
			Configuration::updateValue('ALLOW_TO_SELECT_ORDER_IN_FO',(int)Tools::getValue('ALLOW_TO_SELECT_ORDER_IN_FO',1));
			Configuration::updateValue('ALLOW_TO_SELECT_PRIORITY_IN_FO',(int)Tools::getValue('ALLOW_TO_SELECT_PRIORITY_IN_FO',1));
			Configuration::updateValue('ALLOW_TO_UPLOAD_FILE_IN_FO',(int)Tools::getValue('ALLOW_TO_UPLOAD_FILE_IN_FO',1));
			Configuration::updateValue('WORKING_TIME',Tools::getValue('WORKING_TIME','08:00-12:00 GMT+7;13:30-17:00 GMT+7'));
			Configuration::updateValue('WORKING_DAY',implode (",",Tools::getValue('WORKING_DAY','')));
			Configuration::updateValue('PS_TIMEZONE',Tools::getValue('PS_TIMEZONE',''));
			
			$arr = array ('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
			foreach ($arr as $item) {
				$fo = Tools::getValue($item.'_h','').":".Tools::getValue($item.'_m','')." ".Tools::getValue($item.'_b','');
				$to = Tools::getValue($item.'_th','').":".Tools::getValue($item.'_tm','')." ".Tools::getValue($item.'_tb','');
				$foand = Tools::getValue($item.'_hand','').":".Tools::getValue($item.'_mand','')." ".Tools::getValue($item.'_band','');
				$toand = Tools::getValue($item.'_thand','').":".Tools::getValue($item.'_tmand','')." ".Tools::getValue($item.'_tband','');
				Configuration::updateValue('WORKING_TIME_'.$item,$fo."-".$to.";".$foand."-".$toand);
			}
			$msg = '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="Confirmation" />Settings Genaral Tab</div>';
			$_GET['tabs']=0;
		}
		if (Tools::isSubmit('submitGatewayTab')){
			Configuration::updateValue('ZHELPDESK_SERVER',Tools::getValue('ZHELPDESK_SERVER',''));
			Configuration::updateValue('ZHELPDESK_USER',Tools::getValue('ZHELPDESK_USER',''));
			Configuration::updateValue('ZHELPDESK_PASSWORD',Tools::getValue('ZHELPDESK_PASSWORD',''), true);
			Configuration::updateValue('ZHELPDESK_ENCRYPTION',Tools::getValue('ZHELPDESK_ENCRYPTION',''));
			Configuration::updateValue('ZHELPDESK_PORT',Tools::getValue('ZHELPDESK_PORT',''));
			Configuration::updateValue('ZHELPDESK_DEFAULF_DEPARTMENT',Tools::getValue('ZHELPDESK_DEFAULF_DEPARTMENT',''));
			$msg = '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="Confirmation" />Settings Gateway Tab</div>';
			$_GET['tabs']=1;
		}
		if (Tools::isSubmit('submitEmailTemplate')){
			$va = array ('NEW_TICKET_TEMPLATE_FOR_STAFF','UD_TICKET_TEMPLATE_FOR_STAFF','UD_TICKET_TEMPLATE_FOR_CUSTOMER','ASSIGNED_TICKET_TEMPLATE','MISSED_TICKET_TEMPLATE');
			$langs = Language::getLanguages (false);
			$array = array ();
			foreach ($va as $v) {				
				foreach ($langs as $lang) {
					$array [$v][$lang['id_lang']] = Tools::getValue($v.'_'.$lang['id_lang']);
				}
				Configuration::updateValue($v,$array [$v],true);
			}
			$msg = '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="Confirmation" />Settings Email Template Tab</div>';
			Configuration::loadConfiguration ();
			$_GET['tabs']=2;
		}
		if (Tools::isSubmit('submitFrontOfficeTab')){
			Configuration::updateValue('ZHD_NB_MESS_D_TICKET',Tools::getValue('ZHD_NB_MESS_D_TICKET',10));
			Configuration::updateValue('ZHD_COLUMN',Tools::getValue('ZHD_COLUMN',0));
			Configuration::updateValue('ZHD_NB_LIST_TICKET',Tools::getValue('ZHD_NB_LIST_TICKET',10));
			Configuration::updateValue('ZHD_BLOCK_MY_ACCOUNT',Tools::getValue('ZHD_BLOCK_MY_ACCOUNT',1));
			$msg = '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="Confirmation" />Settings Front Office Tab</div>';
			$_GET['tabs']=3;
		}
		
		echo $msg;
	}
	
	/*
	 * Display configuration page of module.
	 * 
	 * @return string html
	 */
	public function getContent() 
	{
		$this->_postProcess();
		return '<h2>'.$this->displayName.'</h2>'.$this->_displayForm();
	}
	
	/**
	 * display Form Config (All tab)
	 * 
     * @return string html
	 */
	protected function _displayFormConfig()
	{
		global $cookie,$currentIndex;

		$output= '
			<script type="text/javascript">
			
				var pos_select = '.(($tab = Tools::getValue('tabs')) ? $tab : '0').';
				$(document).ready(function(){
					$(\'#id_mvt_reason\').change(function(){
						updateMvtStatus($(this).val());
					});
					updateMvtStatus($(this).val());
				});
				function updateMvtStatus(id_mvt_reason)
				{
					if (id_mvt_reason == -1)
						return $(\'#mvt_sign\').hide();
					if ($(\'#id_mvt_reason option:selected\').attr(\'rel\') == -1)
						$(\'#mvt_sign\').html(\'<img src="../img/admin/arrow_down.png" /> '.$this->l('Decrease your stock').'\');
					else
						$(\'#mvt_sign\').html(\'<img src="../img/admin/arrow_up.png" /> '.$this->l('Increase your stock').'\');
					$(\'#mvt_sign\').show();
				}
			</script>
			<script src="../js/tabpane.js" type="text/javascript"></script>
			<link type="text/css" rel="stylesheet" href="../css/tabpane.css" />
			<form action="'.$_SERVER['REQUEST_URI'].'&token='.Tools::getValue('token').'" method="post" enctype="multipart/form-data" name="product" id="product">
			<input type="hidden" name="tabs" id="tabs" value="0" />
				<div class="tab-pane" id="tabPanePL">
				';
				$output.=$this->displayGeneralTab();
				$output.=$this->displayGatewayTab();
				$output.=$this->displayEmaiTemplateTab();
				$output.=$this->displayFrontOfficeTab();
				$output.= '
			<script type="text/javascript">
				var toload = new Array();
				function loadTab(id) {
				if (toload[id]) {
					$.post(
						"'.dirname($currentIndex).'/ajax.php", {
							ajaxProductTab: id,
							token: \''.Tools::getValue('token').'\',
							id_category: '.(int)(Tools::getValue('id_category')).'},
						function(rep) {
							$("#step" + id).html(rep);var languages = new Array();
						}
					)
				}
			}
			</script>
		</div>';
		$output.='
			<div class="clear"></div>
			<br />
		</form>';

		$this->_html .= $output;
		
	}
	
	/**
	 * Display form General Settings
	 * 
	 * @return string html
	 */
	private function _displayFormGeneral()
	{
		return '';
	}
	/**
	 * Display 	General tab
	 */
	function displayGeneralTab()
	{
		global $currentIndex, $cookie, $link;
		$output= '
		<div class="tab-page" id="step1">
			<h4 class="tab">1. '.$this->l('General').'</h4>
			<hr class="clear">
			<br>
			';
				$output.= $this->addElement('text',
					array (
						'label' => 'Notify missed ticket',
						'name' => 'ZHELPDESK_NOTIFY_MISSED_TICKET',
						'value' => 'ZHELPDESK_NOTIFY_MISSED_TICKET',
						'note' => 'How many time to determine ticket whether missed or not. If it is 0, do not determine',
						'expand' =>'Hour' 
					)	
				);
				$output.= $this->addElement('text',
					array (
						'label' => 'Notify Staff Interval',
						'name' => 'NOTIFY_STAFF_INTERVAL',
						'value' => 'NOTIFY_STAFF_INTERVAL',
						'note' => 'Repeat to notify staff for missed ticket after interval. If it is 0, do not determine',
						'expand' =>'Hour' 
					)	
				);
				$output.= $this->addElement('text',
					array (
						'label' => 'Auto-close time',
						'name' => 'AUTO_CLOSE_TIME',
						'value' => 'AUTO_CLOSE_TIME',
						'note' => 'Repeat to notify staff for missed ticket after interval. If it is 0, do not determine',
						'expand' =>'Hour' 
					)	
				);
				$output.= $this->addElement('yesno',
					array (
						'label' => 'Allow to select order in FrontOffice',
						'name' => 'ALLOW_TO_SELECT_ORDER_IN_FO',
						'value' => Configuration::get('ALLOW_TO_SELECT_ORDER_IN_FO'),
						'note' => ''
					)	
				);
				$output.= $this->addElement('yesno',
					array (
						'label' => 'Allow to select priority in FrontOffice',
						'name' => 'ALLOW_TO_SELECT_PRIORITY_IN_FO',
						'value' => Configuration::get('ALLOW_TO_SELECT_PRIORITY_IN_FO'),
						'note' => ''
					)	
				);
				$output.= $this->addElement('yesno',
					array (
						'label' => 'Allow to upload file in FrontOffice',
						'name' => 'ALLOW_TO_UPLOAD_FILE_IN_FO',
						'value' => Configuration::get('ALLOW_TO_UPLOAD_FILE_IN_FO'),
						'note' => ''
					)	
				);
				
				$timezones = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT name FROM '._DB_PREFIX_.'timezone');
				$output.= $this->addElement('select',
					array (
						'label' => 'Time Zone',
						'name' => 'PS_TIMEZONE',
						'values' => $timezones,
						'value' => 'PS_TIMEZONE',
						'note' => '',
						'style' => ''
					)	
				);
				
				$output.= $this->addElement('checkbox',
					array (
						'label' => 'Working Day',
						'name' => 'WORKING_DAY',
						'field' => array (
										'Monday',
										'Tuesday',
										'Wednesday',
										'Thursday',
										'Friday',		
										'Saturday',
										'Sunday'
									),
						'value' => explode(',',Configuration::get('WORKING_DAY')),
						'note' => ''
					)	
				);
				
				$output .= '<center><input style="width:100px !important;" type="submit" name="submitGenaralTab" value="'.$this->l('Save').'" class="button" /></center>';
			$output.= '</div>';
			return $output;
	}
	/**
	 * Display Gateway tab 
	 */
	function displayGatewayTab()
	{
		global $cookie, $currentIndex, $attributeJs, $images, $link;
		$output = 
		'<div class="tab-page" id="step2">
			<h4 class="tab">2. '.$this->l('Gateway').'</h4>
			<hr/>
			<br>
			';
				$output.= $this->addElement('text',
					array (
						'label' => 'Server',
						'name' => 'ZHELPDESK_SERVER',
						'value' => 'ZHELPDESK_SERVER',
						'note' => 'SMTP server' 
					)	
				);
				$output.= $this->addElement('text',
					array (
						'label' => 'Username',
						'name' => 'ZHELPDESK_USER',
						'value' => 'ZHELPDESK_USER',
						'note' => 'Account’s used to login SMTP server'
					)	
				);
				$output.= $this->addElement('text',
					array (
						'label' => 'Password',
						'name' => 'ZHELPDESK_PASSWORD',
						'value' => 'ZHELPDESK_PASSWORD',
						'note' => 'Account password',
						'type' => 'password'
					)	
				);
				
				$output.= $this->addElement('select',
					array (
						'label' => 'Encryption',
						'name' => 'ZHELPDESK_ENCRYPTION',
						'values' => array (
									0 => array ('name'=>'None','value'=>'None'),
									1 => array ('name'=>'TLS','value'=>'TLS'),
									2 => array ('name'=>'SSL','value'=>'SSL'),
									),
						'value' => 'ZHELPDESK_ENCRYPTION',
						'note' => '',
						'style' => 'width:100px;'
					)	
				);
				
				$output.= $this->addElement('text',
					array (
						'label' => 'Port',
						'name' => 'ZHELPDESK_PORT',
						'value' => 'ZHELPDESK_PORT',
						'note' => ''
					)	
				);
				$department = ZDepartmentObject::getAllDepartMent ($cookie->id_lang);
				$output.= $this->addElement('select',
					array (
						'label' => 'Default Department',
						'name' => 'ZHELPDESK_DEFAULF_DEPARTMENT',
						'values' => $department,
						'value' => 'ZHELPDESK_ENCRYPTION',
						'note' => 'It \'s used to assign department for creating new ticket from mail.',
						'style' => 'min-width:100px;',
						'expand' =>''
					)	
				);
				$output .= 
				'<center>
					<input style="width:170px !important;" type="button" name="checkGateway" id="checkGateway" value="'.$this->l('Check Gateway Connection').'" class="button" />
					<input style="width:100px !important;" type="submit" name="submitGatewayTab" value="'.$this->l('Save').'" class="button" /></center>
		</div>';
		$output .= $this->loadJsCheckGatewayConnection();
		return $output;
	}
	
	function loadJsCheckGatewayConnection() 
	{
		return '
		<script type="text/javascript">
		$(document).ready(function() {
			$("body").append(\'<div style="display:none;z-index:500;position:fixed;border:2px solid #999999;background-color:#FFFFFF;top:35%;left:40%;width:250px;" id="my-loading"><img alt="Loading..." src="'._MODULE_DIR_.'zhelpdesk/img/loading44.gif"></div>\');
			$("#checkGateway").click(function() {
				$("#my-loading").show(400);
				
				var host 		= $("#ZHELPDESK_SERVER").val();
				var user 		= $("#ZHELPDESK_USER").val();
				var password 	= $("#ZHELPDESK_PASSWORD").val();
				var ssl 		= $("#ZHELPDESK_ENCRYPTION").val();
				var port 		= $("#ZHELPDESK_PORT").val();
		
				var loadUrl		= "'._MODULE_DIR_.'zhelpdesk/ajax/check_gateway_connection.php";
		
				$.get(loadUrl, {
					host: host, user: user, password: password, port: port, ssl: ssl},
					function(responseText){
						$("#my-loading").hide("fast", function() {
							alert(responseText);
						});
					},
					"html"
					);
			});
		});
		</script>';
	}
	
	/**
	 * Display 	Email Template tab
	 */
	function displayEmaiTemplateTab()
	{
		global $cookie, $currentIndex, $attributeJs, $images;
		$langtags = 'NEW_TICKET_TEMPLATE_FOR_STAFF¤UD_TICKET_TEMPLATE_FOR_STAFF¤UD_TICKET_TEMPLATE_FOR_CUSTOMER¤ASSIGNED_TICKET_TEMPLATE¤MISSED_TICKET_TEMPLATE';
		$output= $this->loadTinyMCE ();
		$output.= '
		<div class="tab-page" id="step3">
			<h4 class="tab">3. '.$this->l('Email Template').'</h4>
			<hr/>
			<br>';
				$output.= $this->addElement('textarea',
					array (
						'label' => 'New ticket template for staff',
						'name' => 'NEW_TICKET_TEMPLATE_FOR_STAFF',
						'value' => 'NEW_TICKET_TEMPLATE_FOR_STAFF',
						'class' => 'rte',
						'note' => '',
						'langtags' => $langtags
					)	
				,true);
				
				$output.= $this->addElement('textarea',
					array (
						'label' => 'Updated ticket template for staff',
						'name' => 'UD_TICKET_TEMPLATE_FOR_STAFF',
						'value' => 'UD_TICKET_TEMPLATE_FOR_STAFF',
						'class' => 'rte',
						'note' => '',
						'langtags' => $langtags
					)	
				,true);
				
				$output.= $this->addElement('textarea',
					array (
						'label' => 'Updated ticket template for customer',
						'name' => 'UD_TICKET_TEMPLATE_FOR_CUSTOMER',
						'value' => 'UD_TICKET_TEMPLATE_FOR_CUSTOMER',
						'class' => 'rte',
						'note' => '',
						'langtags' => $langtags
					)	
				,true);
				
				$output.= $this->addElement('textarea',
					array (
						'label' => 'Assigned ticket template',
						'name' => 'ASSIGNED_TICKET_TEMPLATE',
						'value' => 'ASSIGNED_TICKET_TEMPLATE',
						'class' => 'rte',
						'note' => '',
						'langtags' => $langtags
					)	
				,true);
				
				$output.= $this->addElement('textarea',
					array (
						'label' => 'Missed ticket template',
						'name' => 'MISSED_TICKET_TEMPLATE',
						'value' => 'MISSED_TICKET_TEMPLATE',
						'class' => 'rte',
						'note' => '',
						'langtags' => $langtags
					)	
				,true);
				
				$output .= '<center><input style="width:100px !important;" type="submit" name="submitEmailTemplate" value="'.$this->l('Save').'" class="button" /></center>';
		$output.= '
		</div>';
		return $output;
	}
	/**
	 * Display config for front office 
	 */
	function displayFrontOfficeTab()
	{
		global $currentIndex, $cookie, $link;
		$output= '
		<div class="tab-page" id="step4">
			<h4 class="tab">4. '.$this->l('Front Office').'</h4>
			<hr class="clear">
			<br>
			';
				$output.= $this->addElement('yesno',
					array (
						'label' => 'Display in Block My Account',
						'name' => 'ZHD_BLOCK_MY_ACCOUNT',
						'value' => Configuration::get('ZHD_BLOCK_MY_ACCOUNT'),
						'note' => ''
					)
				);
				
				$output.= $this->addElement('select',
					array (
						'label' => 'Display Column',
						'name' => 'ZHD_COLUMN',
						'value' => 'ZHD_COLUMN',
						'values' => array (
							0 => array ('name'=>'None','value'=>0),		
							1 => array ('name'=>'Left','value'=>1),
							2 => array ('name'=>'Right','value'=>2)
						),
						'note' => ''
					)
				);
				$output.= $this->addElement('text',
					array (
						'label' => 'Number fields diskplay in list ticket',
						'name' => 'ZHD_NB_LIST_TICKET',
						'value' => 'ZHD_NB_LIST_TICKET',
						'note' => ''
					)
				);
				$output.= $this->addElement('text',
					array (
						'label' => 'Number fields message in dentail ticket',
						'name' => 'ZHD_NB_MESS_D_TICKET',
						'value' => 'ZHD_NB_MESS_D_TICKET',
						'note' => ''
					)
				);
				
				$output .= '<center><input style="width:100px !important;" type="submit" name="submitFrontOfficeTab" value="'.$this->l('Save').'" class="button" /></center>';
			$output.= '</div>';
			return $output;
	}
	
	/**
	 * 
	 * @see modules/zhelpdesk/lib/zprofess/Zhelpdeskmodule::loadTinyMCE()
	 */
	public function loadTinyMCE()
	{
		global $cookie;
		$defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
		$languages = Language::getLanguages(false);
		$iso = Language::getIsoById((int)$cookie->id_lang);
		$content = '';
		if (version_compare(_PS_VERSION_, '1.4.0.0') >= 0)
			$content .= '
			<script type="text/javascript">	
				var iso = \''.(file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en').'\' ;
				var pathCSS = \''._THEME_CSS_DIR_.'\' ;
				var ad = \''.dirname($_SERVER['PHP_SELF']).'\' ;
			</script>
			<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tiny_mce/tiny_mce.js"></script>
			<script type="text/javascript" src="'._MODULE_DIR_.'zhelpdesk/js/tinymce.inc.js"></script>
			<script language="javascript">id_language = Number('.$defaultLanguage.');</script>';
		else
		{
			$content .= '
			<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
			<script type="text/javascript">
				tinyMCE.init({
					mode : "textareas",
					theme : "advanced",
					plugins : "safari,pagebreak,style,layer,table,advimage,advlink,inlinepopups,media,searchreplace,contextmenu,paste,directionality,fullscreen",
					theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
					theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,,|,forecolor,backcolor",
					theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,media,|,ltr,rtl,|,fullscreen",
					theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,pagebreak",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					theme_advanced_statusbar_location : "bottom",
					theme_advanced_resizing : false,
					content_css : "'.__PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/global.css",
					document_base_url : "'.__PS_BASE_URI__.'",
					width: "600",
					height: "auto",
					font_size_style_values : "8pt, 10pt, 12pt, 14pt, 18pt, 24pt, 36pt",
					template_external_list_url : "lists/template_list.js",
					external_link_list_url : "lists/link_list.js",
					external_image_list_url : "lists/image_list.js",
					media_external_list_url : "lists/media_list.js",
					elements : "nourlconvert",
					entity_encoding: "raw",
					convert_urls : false,
					language : "'.(file_exists(_PS_ROOT_DIR_.'/js/tinymce/jscripts/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en').'"
				});
				id_language = Number('.$defaultLanguage.');
			</script>';
		}
		return $content;
	}
	
}